package com.func.domain.strategy.service.rule.chain.impl;

import com.func.domain.strategy.service.armory.IStrategyDispatch;
import com.func.domain.strategy.service.rule.chain.AbstractLogicChain;
import com.func.domain.strategy.service.rule.chain.factory.DefaultLogicChainFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @ClassName DefaultLogicChainFactory
 * @Description 责任链兜底的抽奖策略, 默认的最简单的执行一次抽奖的策略
 * @Author: func
 * @Date 2025/2/28 12:46
 * @Version 1.0
 */

@Slf4j
@Component("default")
public class DefaultLogicChain extends AbstractLogicChain {
    @Resource
    private IStrategyDispatch strategyDispatch;

    @Override
    public DefaultLogicChainFactory.StrategyAwardVO logic(String userId, Long strategyId) {
        Integer awardId = strategyDispatch.getRandomAwardId(strategyId);
        log.info("抽奖责任链-默认处理 userId : {}, strategyId : {}, awardId : {}", userId, strategyId, awardId);
        return DefaultLogicChainFactory.StrategyAwardVO.builder()
                .awardId(awardId)
                .logicModel(ruleModel())
                .build();
    }

    @Override
    public String ruleModel() {
        return DefaultLogicChainFactory.LogicModel.RULE_DEFAULT.getCode();
    }
}
